﻿// // -------------------------------------------------------------------------------------
// // Copyright 2012 ELEN7046 Group 2
// // 
// // Last Modified on: 2012-06-10
// // 
// // Contributors:
// // 
// // Amith Sewnarain
// // Elmar Vosloo
// // Jason Thorne
// // Satish Jewan
// // 
// // Wits University 
// // School of Electrical & Information Engineering
// // Software Engineering Tools and Techniques
// // 
// // -------------------------------------------------------------------------------------
// // 
// // This file is part of the DishDash Event Visualization System.
// // 
// // DishDash is free software: you can redistribute it and/or modify
// // it under the terms of the GNU General Public License as published by
// // the Free Software Foundation, either version 3 of the License, or
// // (at your option) any later version.
// // 
// // DishDash is distributed in the hope that it will be useful,
// // but WITHOUT ANY WARRANTY; without even the implied warranty of
// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// // GNU General Public License for more details.
// // 
// // You should have received a copy of the GNU General Public License
// // along with DishDash.  
// // If not, see <http://www.gnu.org/licenses/>.
// // -------------------------------------------------------------------------------------

var dishdash = dishdash || { };
dishdash.services = dishdash.services || { };

dishdash.services.EventFetchingClientSideService = function() {

//CONTRIB: Amith
    this.GetAllCategories = function(callback) {
        var ajaxOptions = {
            url: "/DishDashboard/EventFetchingService?Op=GetCategories",
            type: "POST",
            dataType: "JSON",
            complete: function(xmlHttpRequest, status) {
                try {
                    var response = JSON.parse(xmlHttpRequest.responseText);
                    callback(response);
                } catch(e) {
                    alert("an error occurred");
                }
            },
            contentType: "application/json; charset=\"utf-8\""
        };

        $.ajax(ajaxOptions);
    };

    //CONTRIB: Elmar
    this.GetCategoryData = function(request, callback) {

        var ajaxOptions = {
            url: "/DishDashboard/EventFetchingService?Op=GetCategoryData",
            type: "POST",
            dataType: "JSON",
            data: JSON.stringify(request),
            complete: function(xmlHttpRequest, status) {
                try {
                    var response = JSON.parse(xmlHttpRequest.responseText);
                    callback(response);
                } catch(e) {
                    alert(e);
                }
            },
            contentType: "application/json; charset=\"utf-8\""
        };
        $.ajax(ajaxOptions);
    };
    this.GetCategoryDataByPrecision = function(request, callback) {

        var ajaxOptions = {
            url: "/DishDashboard/EventFetchingService?Op=GetCategoryDataByPrecision",
            type: "POST",
            dataType: "JSON",
            data: JSON.stringify(request),
            complete: function(xmlHttpRequest, status) {
                try {
                    var response = JSON.parse(xmlHttpRequest.responseText);
                    callback(response);
                } catch(e) {
                    alert(e);
                }
            },
            contentType: "application/json; charset=\"utf-8\""
        };
        $.ajax(ajaxOptions);
    };
    this.GetAggregatedEventCountByEventType = function(request, callback) {

        var ajaxOptions = {
            url: "/DishDashboard/EventFetchingService?Op=GetAggregatedEventCountByEventType",
            type: "POST",
            dataType: "JSON",
            data: JSON.stringify(request),
            complete: function(xmlHttpRequest, status) {
                try {
                    var response = JSON.parse(xmlHttpRequest.responseText);
                    callback(response);
                } catch(e) {

                    alert(e);
                }
            },
            contentType: "application/json; charset=\"utf-8\""
        };
        $.ajax(ajaxOptions);
    };
    this.AggregateEventCountByContextValue = function(request, callback) {

        var ajaxOptions = {
            url: "/DishDashboard/EventFetchingService?Op=AggregateEventCountByContextValue",
            type: "POST",
            dataType: "JSON",
            data: JSON.stringify(request),
            complete: function(xmlHttpRequest, status) {
                try {
                    var response = JSON.parse(xmlHttpRequest.responseText);
                    callback(response);
                } catch(e) {

                    alert(e);
                    //alert(e.Message.toString);
                }
            },
            contentType: "application/json; charset=\"utf-8\""
        };
        $.ajax(ajaxOptions);
    };
};